/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.cmmp.uac.pages.entity;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import org.apache.wicket.extensions.markup.html.tree.table.ColumnLocation;
import org.apache.wicket.extensions.markup.html.tree.table.ColumnLocation.Alignment;
import org.apache.wicket.extensions.markup.html.tree.table.ColumnLocation.Unit;
import org.apache.wicket.extensions.markup.html.tree.table.IColumn;
import org.apache.wicket.extensions.markup.html.tree.table.PropertyRenderableColumn;
import org.apache.wicket.extensions.markup.html.tree.table.PropertyTreeColumn;
import org.apache.wicket.extensions.markup.html.tree.table.TreeTable;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.eelpo.cmmp.core.exception.ServiceException;
import com.eelpo.cmmp.core.wicket.page.extensions.SerachContentWebPage;
import com.eelpo.cmmp.uac.dao.vo.Entity;
import com.eelpo.cmmp.uac.services.IEntityManageService;
import com.eelpo.cmmp.uac.session.UACSession;

/**
 * <pre>
 * 
 * 业务实体管理
 * 
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class EntityManage extends SerachContentWebPage<Entity> {

	@SpringBean
	private IEntityManageService entityManageService;

	/**
	 * @param title
	 */
	public EntityManage() {
		super("业务实体管理", new Entity());
	}

	@Override
	public Panel renderSearchPanel(String id) {
		return new EntitySearchPanel(id, getParameter());
	}

	@Override
	public Panel renderSearchContentPanel(String id) {

		DefaultTreeModel treeModel = null;

		try {
			treeModel = entityManageService.getMenuEntities(UACSession.get().getUserId());
		} catch (ServiceException e) {
			treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
		}

		IColumn columns[] = new IColumn[] { new PropertyTreeColumn(new ColumnLocation(Alignment.LEFT, 25, Unit.PERCENT), "实体名称", "userObject.name"),
				new PropertyRenderableColumn(new ColumnLocation(Alignment.LEFT, 35, Unit.PERCENT), "实体代码", "userObject.code"),
				new PropertyRenderableColumn(new ColumnLocation(Alignment.LEFT, 6, Unit.PERCENT), "实体类型", "userObject.type.name"),
				new PropertyRenderableColumn(new ColumnLocation(Alignment.LEFT, 6, Unit.PERCENT), "实体次序", "userObject.index"),
				new PropertyRenderableColumn(new ColumnLocation(Alignment.LEFT, 6, Unit.PERCENT), "实体状态", "userObject.status.label")};

		TreeTable entityTree = new TreeTable(id, treeModel, columns);
		entityTree.setRootLess(true);
		entityTree.getTreeState().setAllowSelectMultiple(false);
		return entityTree;
	}
}
